package TestCases;

import java.util.ArrayList;

import org.junit.Test;

import static org.junit.Assert.*;
import fxTrader.algorithm.TrendFinder;
import fxTrader.presentation.TrendReporter;
import fxTrader.retriever.CurrencyRetriever;

import updater.currency.data.Currency;
import junit.framework.TestCase;

public class fx_finder_test extends TestCase {
	private static ArrayList<Currency> currencyList;
	private static TrendFinder trendFinder;
	private static TrendReporter trendReporter;
	
	
	//Result list [0] : CurrentRate    , Result list [1] : Average_10Days
	//Result list [2] : Average_20Days , Result list [3] : Average_50Days
	//Result list [4] : Max_5Days      , Result list [5] : Max_1Month
	//Result list [6] : Min_5Days      , Result list [7] : Min_1Month
	@Test
	public double[] getResultList() { 
	
		currencyList = new ArrayList<Currency>();
		currencyList = CurrencyRetriever.getCurrencyListBySymbol("TEST");

		trendFinder = new TrendFinder();
		trendReporter = new TrendReporter();
		double[] result = trendFinder.getResultList(currencyList);
		
		return result;
	}
	@Test
	public void testCase_1_Average_10Day() {
		double[] resultSet = getResultList();
		double result = resultSet[1];
		assertEquals(result, 0.0844);
	}
	@Test
	public void testCase_2_Average_20Day() {
		double[] resultSet = getResultList();
		double result = resultSet[2];
		assertEquals(result, 0.0865);
	}
	@Test
	public void testCase_3_Average_50Day() {
		double[] resultSet = getResultList();
		double result = resultSet[3];
		assertEquals(result, 0.0868);
	}
	@Test
	public void testCase_4_MAX_5D() {
		double[] resultSet = getResultList();
		double result = resultSet[4];
		assertEquals(result, 0.094);
	}
	@Test
	public void testCase_5_MAX_1M() {
		double[] resultSet = getResultList();
		double result = resultSet[5];
		assertEquals(result, 0.0948);
	}
	@Test
	public void testCase_6_MIN5D() {
		double[] resultSet = getResultList();
		double result = resultSet[6];
		assertEquals(result, 0.0779);
	}
	@Test
	public void testCase_7_MIN1M() {
		double[] resultSet = getResultList();
		double result = resultSet[7];
		assertEquals(result, 0.0779);
	}
	@Test
	public void testCase_8_MakeDecision_1_s() {
		
		currencyList = new ArrayList<Currency>();
		currencyList = CurrencyRetriever.getCurrencyListBySymbol("JPY");

		trendFinder = new TrendFinder();
		boolean result = trendFinder.MakeDecision_shortTrade(currencyList);
		assertEquals(result, true);
	}
	@Test
	public void testCase_9_MakeDecision_2_s() {
		
		currencyList = new ArrayList<Currency>();
		currencyList = CurrencyRetriever.getCurrencyListBySymbol("JPY");

		Currency c1 = new  Currency();
		c1.setPrice("10");
		currencyList.set(50, c1);
		
		trendFinder = new TrendFinder();
		boolean result = trendFinder.MakeDecision_shortTrade(currencyList);
		assertEquals(result, true);
	}
	
	@Test
	public void testCase_8_MakeDecision_1_l() {
		
		currencyList = new ArrayList<Currency>();
		currencyList = CurrencyRetriever.getCurrencyListBySymbol("JPY");

		trendFinder = new TrendFinder();
		boolean result = trendFinder.MakeDecision_longTrade(currencyList);
		assertEquals(result, true);
	}
	@Test
	public void testCase_9_MakeDecision_2_l() {
		
		currencyList = new ArrayList<Currency>();
		currencyList = CurrencyRetriever.getCurrencyListBySymbol("JPY");

		Currency c1 = new  Currency();
		c1.setPrice("10");
		currencyList.set(50, c1);
		
		trendFinder = new TrendFinder();
		boolean result = trendFinder.MakeDecision_longTrade(currencyList);
		assertEquals(result, true);
	}
	
	@Test
	public void testCase_10_reporter_s() {
		
		currencyList = new ArrayList<Currency>();
		currencyList = CurrencyRetriever.getCurrencyListBySymbol("TEST");

		trendFinder = new TrendFinder();
		trendReporter.displayConsultation_shortTrend(true,trendFinder.getResultList(currencyList));
		boolean result = true;
		assertEquals(result,true );
	}
	
	@Test
	public void testCase_11_reporter_s() {
		
		currencyList = new ArrayList<Currency>();
		currencyList = CurrencyRetriever.getCurrencyListBySymbol("TEST");

		trendFinder = new TrendFinder();
		trendReporter.displayConsultation_shortTrend(false,trendFinder.getResultList(currencyList));
		boolean result = true;
		assertEquals(result,true );
	}
	
	@Test
	public void testCase_12_reporter_l() {
		
		currencyList = new ArrayList<Currency>();
		currencyList = CurrencyRetriever.getCurrencyListBySymbol("TEST");

		trendFinder = new TrendFinder();
		trendReporter.displayConsultation_longTrend(true,trendFinder.getResultList(currencyList));
		boolean result = true;
		assertEquals(result,true );
	}
	
	@Test
	public void testCase_13_reporter_l() {
		
		currencyList = new ArrayList<Currency>();
		currencyList = CurrencyRetriever.getCurrencyListBySymbol("TEST");

		trendFinder = new TrendFinder();
		trendReporter.displayConsultation_longTrend(false,trendFinder.getResultList(currencyList));
		boolean result = true;
		assertEquals(result,true );
	}
	
}